<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>管理员界面修改</title>
	<link rel="icon" href="/image/favicon.ico" type="image/x-icon">
	<link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet">
	<link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

	<style type="text/css">
		#admin{
			width: 100%;
			box-sizing: border-box;
			padding-left: 30px;
			padding-right: 30px;
		}
		.pagehead{
			background-color: #f5f5f5;
			height: 40px;
		}
		.pagehead h1{
			margin: 0;
			font-size: 18px;
			line-height: 40px;
			padding-left: 12px;
		}
		#bottom{
			margin-top: 20px;
			border-bottom: 2px solid #ff8c00;
		}
		#message{
			margin-top: 30px;
		}
		#message input {
		}
		.text{
			color: red;
		}

	</style>
</head>
<body>
	<div id="admin">
		<div>
			<div class="pagehead">
				<h1>
					<i class="fa fa-pencil" style="color: blue;"></i>&nbsp;&nbsp;您当前的位置：<a href="adminIndex.html"></a>信息修改
				</h1>
			</div>
		</div>
		<div id="bottom"></div>
		<div id="message">
			<form role="form" id="update_admin_form">
				<div class="form-group">
					<label for="exampleInputEmail1">管理员昵称</label><input type="email" name="adminName" class="form-control" id="exampleInputEmail1" placeholder="输入5-15位的英文或者数字或者下划线" abc="^\w{5,15}$" err_info="用户名必须是5-15位的英文或者数字或者下划线"  />
				</div>
				<div class="form-group" id="abc">
					<label for="exampleInputPassword1">管理员原来的密码</label><input type="password" name="oldadminPassword" class="form-control old" id="exampleInputPassword1" placeholder="请输入原密码"/>
				</div>
				
				<div class="form-group">
					<label for="exampleInputPassword1">密码修改</label><input type="password" name="adminPassword" class="form-control"  id="exampleInputPassword2" placeholder="输入6-15位的字符或者数字" abc="^[a-z0-9]{6,15}$" err_info="输入密码至少要6-15位"/>
				</div>
				<div class="checkbox">
					<label><input type="checkbox" />同意并修改</label>
				</div> <button onclick="submitAdmin('update_admin_form')" type="button" class="btn btn-default">提交</button>
			</form>
		</div>
	</div>


</div>

<script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.2.2/jquery.js"></script>
<script src="https://cdn.bootcss.com/twitter-bootstrap/3.4.0/js/bootstrap.min.js"></script>

<script type="text/javascript">
	$(function (){  
		$('.form-group').find('[abc]').on('input',function(){
					var regStr = $(this).attr('abc');  //获取正则属性
					var reg = new RegExp(regStr);     //创建正则对象
					var info = $(this).attr('err_info') || "输入错误"; //获取错误提示
					
					$(this).nextAll().remove();
					if(reg.test($(this).val()) ) {
					}else{
						$(this).after('<span>'+info+'</span>');
					}
					$('span').addClass('text');
				});
	}); 
	function submitAdmin(fomId) {
		var fom = document.getElementById(fomId);
		var formData =  new FormData(fom);

		$.ajax({
          //测试地址
           // url:'http://httpbin.org/post', 
           url:'/pan/admin/update', 
           type:'POST',
           data: formData,
          processData: false,  // 告诉jQuery不要去处理发送的数据  
          contentType: false,   // 告诉jQuery不要去设置Content-Type请求头  
          success: function (data) {
          	console.log(data);
          	var code = data.statusCode;
          	var d = data.data;
          	$('#abc').find('.old').nextAll().remove();	
          	if (code==200) {
          		alert("您已修改成功！");
          		$('#exampleInputPassword1').val("");
          		$('#exampleInputPassword2').val("");

          	}else{
          		$('#abc').find('.old').after('<span>'+d+'</span>');
          	}
          	$('span').addClass('text');
          },

          error: function (err) {
          	console.log(err);
          }
      });
	}


</script>
</body>
</html>